﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "PluggableAI/Decisions/Look")]
public class LookDecision : Decision {

    public override bool Decide(StateController stateController)
    {
        bool targetVisible = Look(stateController);
        return targetVisible;
    }

    private bool Look(StateController controller)
    {
        RaycastHit hit;
        float lookRange = 2;
        float lookSphereCastRadius = 1;
        Debug.DrawRay(controller.eyes.position, controller.eyes.forward.normalized * lookRange, Color.green);

        if (Physics.SphereCast(controller.eyes.position, lookSphereCastRadius, controller.eyes.forward, out hit, lookRange)
            && hit.collider.CompareTag("Player"))
        {
            controller.chaseTarget = hit.transform;
            return true;
        }
        else
        {
            return false;
        }
    }
}
